require 'MVVM.Sources.View.Adaptor'

ToggleAdaptor = class('ToggleAdaptor', Adaptor)

function ToggleAdaptor:ctor(gameObject, propertyName, callBack, binder)
    self.component = gameObject:GetComponent('Toggle')
    binder:RegisterEvent(function(viewModel, property)
        self.component.onValueChanged:AddListener(function(isOn)
            local OnToggle = property['OnToggle']
            if OnToggle == nil then
                return
            end
            OnToggle(isOn)
        end)
    end, function()
        self.component.onValueChanged:RemoveAllListeners()
    end, callBack)

    if propertyName~=nil then
        binder:Add(propertyName,function(oldValue,newValue)
            if newValue == nil or oldValue==newValue then
                return
            end
            self.component.isOn = newValue
        end)
    end
end